import { deepCopy } from '../utils/toolsHelper';

/*
 * @Author: MrDotYan 2564217790@qq.com
 * @Date: 2024-09-12 11:32:39
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-12 11:39:07
 * @FilePath: /EqDataProcessWeb/src/views/dataProcess/electricalEngineering/hooks/queue.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export class Queue<T> {
  private items: T[] = [];

  // 入队
  enqueue(item: T): void {
    this.items.push(deepCopy(item));
  }

  // 出队
  dequeue(): T | undefined {
    return this.items.shift();
  }

  // 检查队列是否为空
  isEmpty(): boolean {
    return this.items.length === 0;
  }

  // 获取队列大小
  size(): number {
    return this.items.length;
  }

  // 查看队首元素
  peek(): T | undefined {
    return this.items[0];
  }

  // 清空队列
  clear(): void {
    this.items = [];
  }
}
